
package com.kweative.model.column;

import com.kweative.model.Table;
import java.util.ArrayList;
import java.util.LinkedList;

/**
 *
 * @author henrik
 */
abstract public class ColumnComplex<F extends ColumnComplex,T extends Table> implements IColumn<T> {
	private LinkedList<Column<?,T>> fields = new LinkedList<Column<?,T>>();
	private T table;
    private Class dataType;
	private String name;

	public ColumnComplex(String name,Class dataType) {
		this.name = name;
		this.dataType = dataType;
	}

	public ColumnComplex(Class dataType) {
		this.dataType = dataType;
	}

	public String getName() {
		return name;
	}
	protected void addField(Column f) {
		fields.add(f);
	}
	public Class getDataType() {
		return dataType;
	}

	public void setDataType(Class dataType) {
		this.dataType = dataType;
	}

	public T getTable() {
		return table;
	}

	public void setTable(T table) {
		this.table = table;
		for(Column f:fields) {
			f.setTable(table);
		}
	}

	public String[] getColumnNames() {
		ArrayList<String> result = new ArrayList<String>();

		for(Column f:fields) {
			for(String name: f.getColumnNames()) {
				result.add(name);
			}
		}
		return result.toArray(new String[0]);
	}

    public LinkedList<Column<?,T>> getColumns() {
        return fields;
    }
}
